<template>
  <div class="hm-post-item" @click="postItemClick(artItem.id)">
    <!-- 多图片文章 -->
    <div class="more-img" v-if="artItem.type === 1 && artItem.cover.length !== 1">
      <div class="title txt-cut">{{ artItem.title }}</div>
      <div class="image">
        <img :src="imgItem.url" alt="" v-for="imgItem in artItem.cover" :key="imgItem.id">
      </div>
      <div class="other-info">
        <span class="user">{{ artItem.user.nickname }}</span>
        <span class="comment">{{ artItem.comment_length }}跟帖</span>
      </div>
    </div>
    <!-- 单图片文章 -->
    <div class="one-img" v-else-if="artItem.type === 1 && artItem.cover.length === 1">
      <div class="left">
        <div class="title txt-cut">{{ artItem.title }}</div>
        <div class="other-info">
          <span class="user">{{ artItem.user.nickname }}</span>
          <span class="comment">{{ artItem.comment_length }}跟帖</span>
        </div>
      </div>
      <div class="image">
        <img :src="imgItem.url" alt="" v-for="imgItem in artItem.cover" :key="imgItem.id">
      </div>
    </div>
    <!-- 视频文章 -->
    <div class='vedio' v-else>
      <div class="title one-txt-cut">{{ artItem.title }}</div>
      <img :src="artItem.cover[0].url" alt="">
      <div class="play-btn"><i class="iconfont iconshipin"></i></div>
      <div class="other-info">
        <span class="user">{{ artItem.user.nickname }}</span>
        <span class="comment">{{ artItem.comment_length }}跟帖</span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    artItem: {
      type: Object,
      default () {
        return {}
      }
    }
  },

  methods: {
    postItemClick (id) {
      this.$router.push(`/article/${id}`)
    }
  }
}
</script>

<style lang="scss" scoped>
.hm-post-item {
  padding: 10px;
  border-bottom: 1px solid #eee;
}
.title {
  font-size: 16px;
  color: #333;
}
.other-info {
  margin-top: 10px;
  font-size: 13px;
  color: #868686;
  .user {
    margin-right: 15px;
  }
}
.more-img {
  .image {
    display: flex;
    width: 100%;
    flex-wrap: nowrap;
    justify-content: space-between;
    img {
      display: inline-block;
      width: 110px;
      height: 70px;
      object-fit: cover;
      vertical-align: bottom;
    }
  }
}
.one-img {
  display: flex;
  height: 75px;
  align-items: center;
  .left {
    flex: 1;
    height: 100%;
    margin-right: 10px;
    position: relative;
    .other-info {
      position: absolute;
      bottom: 0;
      left: 0;
      margin: 0;
    }
  }
  .image {
    width: 121px;
    height: 100%;
    img {
      height: 100%;
      object-fit: cover;
    }
  }
}
.vedio {
  position: relative;
  .play-btn {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 46px;
    height: 46px;
    line-height: 46px;
    border-radius: 50%;
    background-color: rgba($color: #8f949a, $alpha: .6);
    border: 0;
    i {
      font-size: 46px;
      vertical-align: middle;
      color: #fff;
    }
  }
}
</style>
